import Cookies from 'js-cookie'
import { defineStore } from 'pinia'
import { getToken, setToken, removeToken } from '@/utils/auth'

const useAppStore = defineStore('app', {
  state: () => ({
    refreshFlag: false,
    activeTab: localStorage.getItem('activeTab') || 'logistics',
    token: getToken(),
    competitions: [
      {
        id: 1,
        icon: '🔄',
        title: '编程任务赛—物流搬运',
        indexName: '编程任务赛—物流搬运',
        description: '通过编程控制机器人完成物流搬运任务',
        key: 'logistics',
        playType: 2,
      },
      {
        id: 2,
        icon: '🔥',
        title: '编程任务赛—灭火挑战',
        indexName: '编程任务赛—灭火挑战',
        description: '设计智能机器人进行火灾救援模拟',
        key: 'fire',
        playType: 1,
      },
      {
        id: 3,
        icon: '🏃',
        title: '极速任务赛',
        indexName: '极速任务赛',
        description: '操控机器人快速通过复杂地形',
        key: 'obstacle',
        playType: 5,
      },
      {
        id: 4,
        icon: '⚽',
        title: '战术大师-棋奕争锋',
        indexName: '战术大师-棋奕争锋',
        description: '现场五子棋对抗',
        key: 'gobang',
        playType: 3,
      },
      {
        id: 5,
        icon: '⚽',
        title: '球形无人机对抗赛',
        indexName: '球形无人机对抗赛',
        description: '开发无人机进行球类运动对抗',
        key: 'drone',
        playType: 4,
      },
    ],
  }),
  actions: {
    setSize(size) {
      this.size = size
    },
    setCompetitions(competitions) {
      this.competitions = competitions
    },
    setToken(token) {
      this.token = token
      setToken(token)
    },
    setActiveTab(activeTab) {
      this.activeTab = activeTab
      localStorage.setItem('activeTab', activeTab)
    },
    setRefreshFlag(flag) {
      this.refreshFlag = flag
    },
  },
})

export default useAppStore
